<?php
require_once '../conn/DBconnect.php'; 
require_once '../utils/phpUtils.php';

	$keyword = "";
	if(isset($_POST["keyword"]))
		$keyword = $_POST["keyword"];
		
	$whereStmt = "pi_first_name like \'". $keyword ."%\' OR pi_last_name like \'". $keyword ."%\' OR pi_email_add like \'". $keyword ."%\'";
	$tableStmt = "participant_info"; 
	$columns = "*";
	$extras = "";
	
	if($keyword == "{COUNT}")
	{
		$whereStmt = $keyword;
		$tableStmt = "";
		$columns = "";
		$extras = "";
	}
	
	$searchSQL = "call SP_SEARCH('". $tableStmt ."','". $columns ."','". $whereStmt ."','". $extras ."');";
	
	if ($result = mysqli_query($mysqlLink, $searchSQL)) {
		
		if($keyword == "{COUNT}")
		{
			while($row = mysqli_fetch_array($result))
			{
			?>
		    	<div class="resultItem">
		    		<div style="width: 150px;"><?php echo $row["reg_desc"]?></div>
			    	<div style="width: 50px;">(<?php echo $row["totalCount"]?>)</div>
		    	</div>
		    <?php
		    }
		}
		else {
	?>
			<div class="resultItem">
		    	<div class="formTitleLabel" style="width: 50px;">CODE</div>
		    	<div class="formTitleLabel" style="width: 150px;">First Name</div>
		    	<div class="formTitleLabel" style="width: 150px;">Last Name</div>
		    	<div class="formTitleLabel" style="width: 30px;">MI</div>
		    	<div class="formTitleLabel" style="width: 250px;">Email Add</div>
		    	<div class="formTitleLabel" style="width: 100px;">Mobile</div>
	    	</div>
	    	<div style="width:100%;"><hr class="hrSolidLine"/></div>
	<?php 
			while($row = mysqli_fetch_array($result))
		    {
		    ?>
		    	<div class="resultItem">
			    	<div style="width: 50px;"><?php echo $row["pi_code"]?></div>
			    	<div style="width: 150px;"><?php echo $row["pi_first_name"]?></div>
			    	<div style="width: 150px;"><?php echo $row["pi_last_name"]?></div>
			    	<div style="width: 30px;">&nbsp;<?php echo $row["pi_middle_initial"]?></div>
			    	<div style="width: 250px;"><?php echo $row["pi_email_add"]?></div>
			    	<div style="width: 100px;"><?php echo $row["pi_mobile_no"]?></div>
		    	</div>
		    	<div style="width:100%;"><hr class="hrSolidLine"/></div>
		    <?php
		    }
	    }
	}
	else
		echo "Unknown error";
	?>